﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GetData
{
    //通过控件获取web跳转最终的url
    public class WebUrlManagerByControllerClass
    {
        WebBrowser webbrowser = null;
        public string lastUrl = ""; 

        public WebUrlManagerByControllerClass()
        {
            webbrowser = new WebBrowser();
            lastUrl = ""; 
        }
        /// <summary>
        /// 通过url获取最终跳转的url
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public string GetWebUrlByWebBrowser(string url)
        {
            webbrowser.Url = new Uri(url);
            webbrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted);
            //这是给wb添加载入完毕的事件
            Thread.Sleep(4000);
            return lastUrl;
        }
        private void wb_DocumentCompleted(object sender, EventArgs e)//这个就是当网页载入完毕后要进行的操作
        {
            lastUrl = webbrowser.Url.ToString();
        }
    }
}
